
package com.scs.application.modules.upms.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.modules.upms.entity.WxmpMember;
import com.scs.application.modules.upms.mapper.WxmpMemberMapper;
import com.scs.application.modules.upms.request.WxmpMemberQueryRequest;
import com.scs.application.modules.upms.service.WxmpMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 服务号成员 service 实现
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class WxmpMemberServiceImpl extends BaseServiceImpl<WxmpMemberMapper, WxmpMember> implements WxmpMemberService {

    @Override
    public List<WxmpMember> list(WxmpMemberQueryRequest request) {
        List<WxmpMember> list = this.list(Wrappers.<WxmpMember>query()
                .orderByDesc("gmt_modified")
        );
        return list;
    }

    @Override
    public IPage<WxmpMember> page(WxmpMemberQueryRequest request) {
        IPage page = this.page(request.getPage(), Wrappers.<WxmpMember>query()
                .orderByDesc("gmt_modified")
        );
        return page;
    }

    @Override
    public List<WxmpMember> listByAppIdAndUserId(String appId, String userId) {
        return this.list(Wrappers.<WxmpMember>query().eq("app_id", appId).eq("user_id", userId));
    }

    @Override
    public WxmpMember findByAppIdAndUserId(String appId, String userId) {
        return this.getOne(Wrappers.<WxmpMember>query().eq("app_id", appId).eq("user_id", userId));
    }

    @Override
    public WxmpMember findByMpKeyAndUserId(String mpKey, String userId) {
        return this.getOne(Wrappers.<WxmpMember>query().eq("mp_key", mpKey).eq("user_id", userId).last("limit 1"));

    }


}
